package com.demo.springcloud.controller;

import com.demo.springcloud.entity.R;
import com.demo.springcloud.service.FeignOrderService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author hxg
 * @version 1.0
 * @date 2021/12/28 9:56
 */
@RestController
//@DefaultProperties(defaultFallback="defaultFallbackMethod")
@RequestMapping("/consumer")
public class feignOrderController {
    @Resource
    private FeignOrderService feignOrderService;

    @GetMapping("/feign/get/{id}")
    public R getOrder(@PathVariable("id")Long id){
        return feignOrderService.get(id);
    }

    @GetMapping("/feign/hystrix/{id}")
    @HystrixCommand(fallbackMethod = "feignOrderFailHandler",commandProperties = {
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="1000")
    })
    //@HystrixCommand
    public String getPaymentFail(@PathVariable("id")Long id){
        return feignOrderService.paymentFail(id);
    }

    public String feignOrderFailHandler(@PathVariable("id")Long id){
        return "feign接口的消费者80报错"+id;
    }

    @GetMapping("/feign/payment/timeoutTest")
    public R timeTest(){
        return feignOrderService.timeoutTest();
    }

    public String defaultFallbackMethod(){
        return "feign接口的消费者80===默认报错";
    }

}
